package cn.ike.web.controller;

import cn.ike.domain.system.User;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {

    // 注入Request对象
    @Autowired
    protected HttpServletRequest request;

    // 注入Response对象
    @Autowired
    protected HttpServletResponse response;  // 编译报错不用管，idea问题

    // 注入Session对象
    @Autowired
    protected HttpSession session;

    /**
     * 获取登录用户所属企业的id
     */
    public String getLoginCompanyId(){
        return getLoginUser().getCompanyId();
    }

    /**
     * 获取登录用户所属企业的名称
     */
    public String getLoginCompanyName(){
        return getLoginUser().getCompanyName();
    }

    //从session中获取登陆用户对象
    protected User getLoginUser(){
        return (User) session.getAttribute("loginUser");
    }
}
